<?php
class v_mysqli extends DB{
	
	public function __construct(& $CONFIGS){
		foreach( $this->db_cfg as $k=>$v ){
			$this->db_cfg[$k] = $CONFIGS[$k];
		}
		$this->conn = $this->connect();
		$this->query("SET NAMES UTF8");
	}

	private function connect(){
		$mysqli = new mysqli($this->db_cfg['dbHost'],$this->db_cfg['dbUser'],$this->db_cfg['dbPwd'],$this->db_cfg['dbName'],$this->db_cfg['dbPort']);
		if( $mysqli->connect_error ){
			echo '<b>Error</b>: '.$mysqli->connect_error; 
			die();
		}
		return $mysqli;
	}

	public function query( $sql="" ){
		if( !empty($sql) ){
			$this->sql = $sql;
		}else{
			$sql = $this->sql;
		}
		return $this->conn->query($sql);
	}

	public function fetch( $result, $result_type=MYSQLI_BOTH ){
		return $result->fetch_array($result_type);
	}

	public function insert_id(){
		return $this->conn->insert_id;
	}

	public function affected_rows(){
		return $this->conn->affected_rows;
	}

	public function close(){
		return $this->conn->close();
	}

	public function error(){
		return $this->conn->errno.':'.$this->conn->error;
	}
}
